<div class="container-fluid">
	<div class="panel panel-default">
		<div class="panel-heading">
			<div class="row">												
				<div class="col-md-12 col-sm-12">
					<div class="btn btn-info" id="create">
						<i class="icon-plus"></i> 新建
					</div>								  
				</div>
			</div>
		</div>
		<div class="panel-body">
			<table class="table table-bordered table-hover table-striped table-condensed">
				<tr>
					<th>资源标识</th>
					<th>资源名称</th>
					<th>资源类型</th>
					<th>创建时间</th>
					<th style="text-align:center; width:80px;">权限</th>
					<th style="text-align:center; width:150px;">管理</th>
				</tr>
				<#if data??> <#list data as resource>
				<tr>
					<td>${resource.uri}</td>
					<td>${resource.name}</td>
					<td>${resource.type}</td>
					<td>${resource.createTime}</td>
					<td class="text-center">					  
						<div class="btn btn-xs btn-info resource2role" data-uri="resource2role.do?resourceId=${resource.id}">
							<i class="icon-magnet"></i> 角色
						</div>
					</td>
					<td class="text-center">	
						<div class="btn btn-xs btn-info resource-edit" data-uri="resource-edit.do?resourceId=${resource.id}">
							<i class="icon-edit "></i> 修改
						</div>	
						<div class="btn btn-xs btn-danger resource-remove" data-uri="${resource.id}">
							<i class="icon-remove"></i> 删除
						</div>												
					</td>
				</tr>
				</#list> </#if>				
			</table>
		</div>
		<div class="panel-footer">
		</div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function() {
		$('#create').on('click', function() {
			$.suredy.showModal({
				size : 'lg',
				icon : 'icon-plus',
				title : '创建安全资源',
				showFoot : false,
				uri : 'resource-create.do'
			});
		});	
		
		$('.resource2role').on('click', function() {
			var $this = $(this);
			$.suredy.showModal({
				size : 'lg',
				icon : 'icon-magnet',
				title : '资源-角色配置',
				showFoot : false,
				uri : $this.data('uri')
			});
		});	
		
		$('.resource-edit').on('click', function() {
			var $this = $(this);
			$.suredy.showModal({
				size : 'lg',
				icon : 'icon-edit',
				title : '修改安全资源',
				showFoot : false,
				uri : $this.data('uri')
			});
		});	
		$('.resource-remove').on('click', function() {
			var resourceId = $(this).data('uri');
			var msg = '是否确认删除当前安全资源？\n\n\
					提示：\n\
					该操作将会删除与安全资源相关的权限配置信息,\n\
					以及解除与安全资源相关的实体资源如菜单|按钮等关联关系,\n\
					请谨慎操作！';

			if (!window.confirm(msg))
				return;
	
			$.ajax({
				url : 'resource-remove.do',
				type : 'POST',
				data : {
					resourceId : resourceId
				},
				success : function(result) {
					console.log(result);
					if (!result) {
						alert('Unknown exception!');
					} else if (!result.success) {
						alert("删除安全资源失败！\n\n" + result.msg);
					} else {
						alert("删除安全资源成功！");
						$.suredy.loadContent('resource-list.do');
					}
				},
				error : function(a, b, c) {
					alert('Server error! ' + b);
				}
			});
		});	
	});
</script>	